package com.poxz.algorithm.luogu.p.p1923;

import java.io.*;
import java.util.*;

/**
 * 求第 k 小的数
 *
 * @author poxz
 */
public class Main {

    static IO IO = new IO();

    public static void main(String[] args) {
        int n,k;
        n = IO.nextInt();
        k = IO.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = IO.nextInt();
        }

        int ans = quickSelect(a, 0, n - 1, k );
        IO.println(ans);

        IO.close();
    }

    static int quickSelect(int[] a, int l, int r, int k) {
        while (l < r) {
            // 随机pivot优化（避免最坏情况）
            int randomIndex = a[r-1];
            swap(a, randomIndex, r);

            int p = partition(a, l, r);

            if (k == p) {
                return a[k];
            } else if (k < p) {
                r = p - 1;
            } else {
                l = p + 1;
            }
        }
        return a[l];
    }

   static int partition(int[] a, int l, int r) {
        int p = a[r];
        int i = l; //记录小于p位置的末尾
        for(int j = l; j < r; j++){
            if(a[j] < p){
                swap(a, i, j);
                i++;
            }
        }
        swap(a, i, r); // 将p放到中间
       return i;
   }

   static void swap(int[] a, int i, int j) {
         int temp = a[i];
         a[i] = a[j];
         a[j] = temp;
   }

    static class IO {
        BufferedReader br;
        StringTokenizer st;
        PrintWriter out;

        IO() {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }

        void print(Object o) {
            out.print(o);
        }


        void println(Object o) {
            out.println(o);
        }

        void println() {
            out.println();
        }

        void printf(String format, Object... args) {
            out.printf(format, args);
        }

        void close() {
            out.flush();
            out.close();
        }
    }
}
